package com.parking.status.sync.netty.server;

import com.parking.status.sync.netty.entity.RequestPre;
import com.parking.status.sync.netty.entity.ResponsePre;
import com.parking.status.sync.netty.entity.ResultCode;
import com.parking.status.sync.netty.event.RequestReceivedEvent;
import com.parking.status.sync.netty.event.RequestReceivedEventParameters;
import com.parking.status.sync.netty.service.EventPublishService;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.util.List;

/**
 * Created by Administrator on 2015/9/18.
 */
@ChannelHandler.Sharable
public class RequestFinalDecoder extends MessageToMessageDecoder<RequestPre>{

    @Autowired
    private EventPublishService service;

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, RequestPre request, List<Object> out) throws Exception {

        RequestReceivedEvent event = new RequestReceivedEvent(
                new RequestReceivedEventParameters(channelHandlerContext, request));
        service.publishEvent(event);

    }

}
